<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="ja" xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml" id="ngsdev-dot-org">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<meta http-equiv="content-script-type" content="text/javascript" />
	<meta http-equiv="content-style-type" content="text/css" />
	<script type="text/javascript" src="../src/AbstractSQL.js"></script>

	<title>AbstractSQL.js test</title>
	<script type="text/javascript">
		var form,code,output,db;
		function init() {
			db = openDatabase("testdb", "1.0", "Test", "1048576");
			form = document.getElementById("testform");
			code = form.code;
			output = form.output;
			onSubmit();
		}
		function outputText(text) {
			output.value = (text||"").toString();
		}
		function onSubmit() {
			try{
				outputText(eval("(function(){;"+code.value+";})();"));
			} catch(e){
				outputText(e);
			}
		}
		function exec(db,sql) {
			db.transaction(function(tx){
				tx.executeSql(sql,[],function(tx,result){
					for (var i=0;i<result.rows.length;++i) {
						console.log(i,result.rows.item(i));
					}
				},function(res,err){
					console.log(res,err);
				});
			});
		
		}
	</script>
	
</head>
<body onload="init();">
<form onsubmit="onSubmit();return false;" id="testform">
<div>
<textarea name="code" style="width:40%;height:200px;float:left;margin-right:1em;">

var sql = new AbstractSQL("test");
//
/*
sql.createTable([
	new AbstractSQL.Field("id",AbstractSQL.FieldType.INTEGER,10,true),
	new AbstractSQL.Field("name",AbstractSQL.FieldType.TEXT,255,false)
	
]);
sql.insert({
  "id":100,
  "name":"長瀬敦史"
})


sql.count("id",[
	new AbstractSQL.Where("name","長")
]);

sql.update({
  name:"あいうえ",
  id:12

},[
	new AbstractSQL.WhereLest(AbstractSQL.Logic.OR,[
		new AbstractSQL.Where("id",100)
	])
],AbstractSQL.Conflict.REPLACE);
*/

sql.insert({
  "id":100,
  "name":"長瀬敦史"
},AbstractSQL.Conflict.REPLACE);

sql.select(["id","name"],[
	new AbstractSQL.WhereLest(AbstractSQL.Logic.OR,[
		new AbstractSQL.Where("id",100),
		new AbstractSQL.Where("id","101")
	])
]);

exec(db,sql);

return sql;

</textarea>
<textarea name="output" style="width:40%;height:200px;float:left;">

</textarea>
</div>
<p style="width:100%;clear:both;margin:0;padding:1em 0 0 0;"><input type="submit" value="eval" /></p>
</form>
</body>
</html>
